package xin.mashibo.genvictobutest.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import xin.mashibo.genvictobutest.R;
import xin.mashibo.genvictobutest.adapter.TransactionAdapter;
import xin.mashibo.genvictobutest.constant.ServiceConstant;
import xin.mashibo.genvictobutest.vo.CardTransactionExtend;

public class TransactionActivity extends AppCompatActivity {


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
        setTitle(R.string.transactionActivityTitle);
        List<CardTransactionExtend> transactionList = getIntent().getBundleExtra(ServiceConstant.TRANSACTION_KEY)
                .getParcelableArrayList(ServiceConstant.TRANSACTION_KEY);
        TransactionAdapter adapter = new TransactionAdapter(this, R.layout.activity_transaction,
                transactionList == null ? new ArrayList<CardTransactionExtend>() : transactionList);
        ListView listView = findViewById(R.id.list_view);
        listView.setAdapter(adapter);
    }


    /**
     * 构建卡片交易信息列表数据
     *
     * @param context 启动的活动
     * @param bundle  bundle
     */
    public static void actionStart(Context context, Bundle bundle) {
        Intent intent = new Intent(context, TransactionActivity.class);
        intent.putExtra(ServiceConstant.TRANSACTION_KEY, bundle);
        context.startActivity(intent);
    }
}
